package 第3节函数;

public class LianXi01 {
    public static void main(String[] args) {
        System.out.println(sumDigits(1234));
        System.out.println(sumDigits(789));
    }
    public static int sumDigits(int num) {
        /*
        1234 % 10 = 4
        123 % 10 = 3
        12 % 10 = 2
        1 % 10 = 1
        0
        */
        int sum = 0;
        while (num != 0) {
            sum += num % 10;
            num /= 10;
        }
        return sum;
    }
}
